package com.voa.web.action;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.team4.util.Validate;
import org.team4.web.action.GenericAction;

import com.voa.domain.Blog;
import com.voa.domain.BlogTags;
import com.voa.service.BlogService;
import com.voa.service.BlogTagsService;
import com.voa.vo.BlogAgg;

/**
 * <p>程序名称：       BlogAction.java</p>
 * <p>程序说明：       日志Action</p>
 * <p>版权信息：       Copyright 深圳市维远泰克科技有限公司</p>
 * <p>时间：          Feb 11, 2011 11:43:02 AM</p>	
 * 
 * @author：          Marker.King
 * @version：         Ver 0.1
 */
@Controller
@Scope("prototype")
public class BlogAction extends GenericAction<Blog> {

	private static final long serialVersionUID = 2208803251575773577L;
	@Autowired
	private BlogService blogService;
	@Autowired
	private BlogTagsService blogTagsService;
	private Date forDate;
	private List<Blog> blogList;
	private List<BlogAgg> blogAggList;
	private List<BlogTags> blogTagsList;
	private Blog blog;
	private Date defaultDate = new Date();
	
	public String search() throws Exception {
		if(SUCCESS.equals(result)) {
			if(Validate.notNull(searchType)) {
				blogList = blogService.searchBlog(searchType, searchValue);
			} else {
				blogList = blogService.findBlog(forDate);
			}
		} else {
			if(Validate.notNull(searchType)) {
				blogAggList = blogService.searchBlogAgg(searchType, searchValue);
			} else {
				blogAggList = blogService.findBlogAgg(forDate);
			}
		}
		return result;
	}
	
	public String toSave() throws Exception {
		blogTagsList = blogTagsService.findOwnBlogTags();
		return SUCCESS;
	}
	
	public String save() throws Exception {
		blogService.saveBlog(blog);
		return result;
	}
	
	public String toUpdate() throws Exception {
		blog = blogService.findBlogById(blog.getId());
		blogTagsList = blogTagsService.findOwnBlogTags();
		return SUCCESS;
	}
	
	public String update() throws Exception {
		blogService.updateBlog(blog);
		return result;
	}

	public List<Blog> getBlogList() {
		return blogList;
	}

	public Date getForDate() {
		return forDate;
	}

	public void setForDate(Date forDate) {
		this.forDate = forDate;
	}

	public List<BlogTags> getBlogTagsList() {
		return blogTagsList;
	}

	public Date getDefaultDate() {
		return defaultDate;
	}

	public Blog getBlog() {
		return blog;
	}

	public void setBlog(Blog blog) {
		this.blog = blog;
	}

	public List<BlogAgg> getBlogAggList() {
		return blogAggList;
	}

	public void setBlogAggList(List<BlogAgg> blogAggList) {
		this.blogAggList = blogAggList;
	}

}
